package cn.qing.service.Impl;

import cn.qing.mapper.MemberMapper;
import cn.qing.mapper.OrderMapper;
import cn.qing.mapper.ProductMapper;
import cn.qing.pojo.Member;
import cn.qing.pojo.Orders;
import cn.qing.pojo.Product;
import cn.qing.service.OrderService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderMapper orderMapper;

    @Autowired
    ProductMapper productMapper;

    @Autowired
    MemberMapper memberMapper;

    /**
     * 分页查询所有的
     * @param page
     * @param size
     * @return
     */
    @Override
    public List<Orders> findAll(Integer page, Integer size) {
        // 使用PageHelper插件进行分页查询
        PageHelper.startPage(page, size);
        List<Orders>  ordersList= orderMapper.findAll();
        return ordersList;
    }

    /**
     * 根据id查询详情
     * @param id
     * @return
     */
    @Override
    public Orders findById(Integer id) {
        Orders orders = orderMapper.findById(id);
        return orders;
    }

    /**
     * 查询所有的产品信息
     * @return
     */
    @Override
    public List<Product> findAllProduct() {
        List<Product> productList = productMapper.findAll();
        return productList;
    }

    /**
     * 查询所有的会员信息
     * @return
     */
    @Override
    public List<Member> findAllMember() {
        List<Member> memberList = memberMapper.findAll();
        return memberList;
    }

    /**
     * 保存订单
     * @param orders
     */
    @Override
    public void save(Orders orders) {
        orderMapper.save(orders);
    }
}
